package com.binguo.api.huawei.imagesearch.Demo;


import com.binguo.api.huawei.imagesearch.ImageSearchService;
import com.binguo.api.huawei.imagesearch.TokenUtil;
import com.binguo.api.huawei.imagesearch.model.RecResult;
import com.binguo.api.huawei.imagesearch.util.HttpClientUtils;
import com.binguo.common.util.JsonUtil;
import org.apache.http.Header;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.json.JSONObject;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import sun.misc.BASE64Decoder;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.*;

public class ImageSearchDemo
{
    private static String ak = "JQMSFHYAJAS043SQKKCC";
    private static String sk = "Y2wO8TrzIuMp9zoFxsWD9jYOMkY1F2y8NRpZT1Bc";
    private static String username = "yunpengai";
    private static String password = "yunpengai.306";
    private static String projectName = "cn-north-1";
    private static String projectId = "15e57275e77c496dbef73cc6ac8c203c";
    private static String instanceName = "15e57275e77c496dbef73cc6ac8c203c";
    private static String recUrl = "https://3339811d307443baa4b1a0e031e4114f.apigw.cn-north-1.huaweicloud.com/v1/infers/9c93c306-d09f-4043-9c9a-1ef4560fc7fd";

    private static String endPointUrl = "https://modelarts.cn-north-1.myhuaweicloud.com";

    public static String token = null;
    public static Date getTokenTime = null;


    public static String getToken() throws Exception{

        boolean flag = true;
        if (getTokenTime != null) {
            Calendar calendar = Calendar.getInstance();

            calendar.add(Calendar.HOUR_OF_DAY, -23);

            if (calendar.getTime().before(getTokenTime)) {
                flag = false;
            }
        }
        if (flag) {
            token = TokenUtil.getToken(username, password, projectName); //获取token
            getTokenTime = new Date();
        }

        return token;
    }
    /**
     * 查询服务监控信息
     */
    public static void training(String serviceId) throws  Exception{
        String url = endPointUrl + "/v1/" + projectId + "/training-jobs";

        try {
            com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
            json.put("job_name", "jgxbShop");//or stopped
            json.put("config", "running");//or stopped
            String requestBody = json.toJSONString();

            System.out.println(requestBody);

            String result = httpGet(url);

            System.out.println(result);

            /**
             * {
             *     "monitors": [
             *         {
             *             "model_id": "2f9dae1b-9fe2-45a6-ba6c-416d31c3792e",
             *             "model_name": "test_ExeML_16bd53cd088",
             *             "model_version": "0.0.1",
             *             "invocation_times": 7,
             *             "failed_times": 0,
             *             "cpu_core_usage": 0,
             *             "cpu_core_total": 2,
             *             "cpu_memory_usage": 0,
             *             "cpu_memory_total": 8192,
             *             "gpu_usage": 0,
             *             "gpu_total": 1
             *         }
             *     ],
             *     "service_id": "49fcaaf4-0ed1-462a-b437-c8910d9e1e72",
             *     "service_name": "service-13a1"
             * }
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 查询服务监控信息
     */
    public static void monitor(String serviceId) throws  Exception{
        String url = endPointUrl + "/v1/" + projectId + "/services/" + serviceId + "/monitor";

        try {
            String result = httpGet(url);

            System.out.println(result);

            /**
             * {
             *     "monitors": [
             *         {
             *             "model_id": "2f9dae1b-9fe2-45a6-ba6c-416d31c3792e",
             *             "model_name": "test_ExeML_16bd53cd088",
             *             "model_version": "0.0.1",
             *             "invocation_times": 7,
             *             "failed_times": 0,
             *             "cpu_core_usage": 0,
             *             "cpu_core_total": 2,
             *             "cpu_memory_usage": 0,
             *             "cpu_memory_total": 8192,
             *             "gpu_usage": 0,
             *             "gpu_total": 1
             *         }
             *     ],
             *     "service_id": "49fcaaf4-0ed1-462a-b437-c8910d9e1e72",
             *     "service_name": "service-13a1"
             * }
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 关闭服务
     */
    public static void stopService(String serviceId) throws  Exception{
        String url = endPointUrl + "/v1/" + projectId + "/services/" + serviceId;

        try {
            com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
            json.put("description", "");//or stopped
            json.put("status", "stopped");//or stopped
            String requestBody = json.toJSONString();

            System.out.println(requestBody);


            String result = httpPut(url, requestBody);

            System.out.println(result);

            /**
             * {
             *
             * }
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 开启服务
     */
    public static void startService(String serviceId) throws  Exception{
        String url = endPointUrl + "/v1/" + projectId + "/services/" + serviceId;

        try {
            com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
            json.put("description", "");//or stopped
            json.put("status", "running");//or stopped
            String requestBody = json.toJSONString();

            System.out.println(requestBody);

            /**
             * {
             *     "description": "",
             *     "status": "running",
             *     "config": [{
             *         "model_id": "xxxx",
             *         "weight": "100",
             *         "specification": "modelarts.vm.cpu.2u",
             *         "instance_count": 1
             *     }]
             * }
             */

            String result = httpPut(url, requestBody);

            System.out.println(result);

            /**
             * {
             *
             * }
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 查询模型服务详情
     */
    public static void getServiceDetail(String serviceId) throws  Exception{
        String url = endPointUrl + "/v1/" + projectId + "/services/" + serviceId;

        try {
            String result = httpGet(url);

            System.out.println(result);

            /**
             * {
             *     "service_id": "49fcaaf4-0ed1-462a-b437-c8910d9e1e72",
             *     "service_name": "service-13a1",
             *     "tenant": "44e0c03b18f740eeb041c1d8077f4fac",
             *     "project": "15e57275e77c496dbef73cc6ac8c203c",
             *     "owner": "867a623098a1451385085a3cb109d9df",
             *     "publish_at": 1562727329958,
             *     "infer_type": "real-time",
             *     "status": "stopped",
             *     "progress": 100,
             *     "access_address": "https://61c3eedafec54ea48720342e1cca29de.apigw.cn-north-1.huaweicloud.com/v1/infers/49fcaaf4-0ed1-462a-b437-c8910d9e1e72",
             *     "workspace_id": "0",
             *     "is_shared": false,
             *     "invocation_times": 7,
             *     "failed_times": 0,
             *     "shared_count": 0,
             *     "config": [
             *         {
             *             "model_id": "2f9dae1b-9fe2-45a6-ba6c-416d31c3792e",
             *             "model_name": "test_ExeML_16bd53cd088",
             *             "model_version": "0.0.1",
             *             "source_type": "auto",
             *             "specification": "modelarts.vm.high.p2",
             *             "status": "notReady",
             *             "weight": 100,
             *             "instance_count": 1,
             *             "scaling": false,
             *             "envs": {}
             *         }
             *     ]
             * }
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询模型服务列表
     */
    public static void getServices() throws  Exception{
        String url = endPointUrl + "/v1/" + projectId + "/services";

        try {
            String result = httpGet(url);

            System.out.println(result);

            /**
             * {
             *     "count": 4,
             *     "total_count": 4,
             *     "services": [
             *         {
             *             "service_id": "49fcaaf4-0ed1-462a-b437-c8910d9e1e72",
             *             "service_name": "service-13a1",
             *             "tenant": "44e0c03b18f740eeb041c1d8077f4fac",
             *             "project": "15e57275e77c496dbef73cc6ac8c203c",
             *             "owner": "867a623098a1451385085a3cb109d9df",
             *             "publish_at": 1562727329958,
             *             "infer_type": "real-time",
             *             "status": "stopped",
             *             "progress": 100,
             *             "invocation_times": 7,
             *             "failed_times": 0,
             *             "is_shared": false,
             *             "shared_count": 0,
             *             "workspace_id": "0"
             *         },
             *         {
             *             "service_id": "e336ef11-872e-405c-af2d-09cb10e47d1b",
             *             "service_name": "test_ExeML_16bd53cd088_V001",
             *             "tenant": "44e0c03b18f740eeb041c1d8077f4fac",
             *             "project": "15e57275e77c496dbef73cc6ac8c203c",
             *             "owner": "867a623098a1451385085a3cb109d9df",
             *             "publish_at": 1562680808876,
             *             "infer_type": "real-time",
             *             "status": "stopped",
             *             "progress": 100,
             *             "invocation_times": 2,
             *             "failed_times": 0,
             *             "is_shared": false,
             *             "shared_count": 0,
             *             "workspace_id": "0"
             *         },
             *         {
             *             "service_id": "bd7ba894-6fb5-4a8a-8c81-0e33c600b7d2",
             *             "service_name": "jayservice0709",
             *             "tenant": "44e0c03b18f740eeb041c1d8077f4fac",
             *             "project": "15e57275e77c496dbef73cc6ac8c203c",
             *             "owner": "867a623098a1451385085a3cb109d9df",
             *             "publish_at": 1562678860923,
             *             "infer_type": "real-time",
             *             "status": "stopped",
             *             "progress": 100,
             *             "invocation_times": 2,
             *             "failed_times": 0,
             *             "is_shared": false,
             *             "shared_count": 0,
             *             "workspace_id": "0"
             *         },
             *         {
             *             "service_id": "cd8cc6a3-90f3-40ec-81a1-9d57f5502144",
             *             "service_name": "exeML-b636_ExeML_16ae4a80610_V001",
             *             "tenant": "44e0c03b18f740eeb041c1d8077f4fac",
             *             "project": "15e57275e77c496dbef73cc6ac8c203c",
             *             "owner": "867a623098a1451385085a3cb109d9df",
             *             "publish_at": 1558617133304,
             *             "infer_type": "real-time",
             *             "status": "stopped",
             *             "progress": 100,
             *             "invocation_times": 23,
             *             "failed_times": 0,
             *             "is_shared": false,
             *             "shared_count": 0,
             *             "workspace_id": "0"
             *         }
             *     ]
             * }
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 数据集创建API
     */
    public static void createDataSet(String dataSetName, String obsDataUrl) throws  Exception{
        String url = endPointUrl + "/v1/" + projectId + "/datasets";

        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        json.put("name", dataSetName);
        json.put("description", "");
        json.put("provider", "OBS");
        json.put("data_url", obsDataUrl);
        json.put("open_obs_version", "true");
        String requestBody = json.toJSONString();

        System.out.println(requestBody);
        try {
            String result = httpPost(url, requestBody);

            System.out.println(result);

            /**
             * {"dataset_id": "2fff8bb3-c6d4-45f8-9a26-eb47b38c0fb4", "task_id": "2b16f332-492a-4f81-b258-074763556d4b"}
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static RecResult restPost(byte[] content, String huaweiUrl){

        try {

            String url = null;
            if (huaweiUrl != null) {
                url = huaweiUrl;
            } else {
                url = recUrl;
            }

            HttpHeaders DEFAULT_JSON_HEADER = new HttpHeaders();
            MediaType jsontype = MediaType.MULTIPART_FORM_DATA;
            DEFAULT_JSON_HEADER.setContentType(jsontype);
            DEFAULT_JSON_HEADER.add("X-Auth-Token", getToken());


            RestTemplate restTemplate = new RestTemplate();

            MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();

            ByteArrayResource contentsAsResource = new ByteArrayResource(content) {
                @Override
                public String getFilename() {
                    return "" + System.currentTimeMillis();
                }
            };
            paramMap.add("images", contentsAsResource);


            HttpEntity entity = new HttpEntity<>(paramMap, DEFAULT_JSON_HEADER);


            ResponseEntity<RecResult> result = restTemplate.postForEntity(url, entity, RecResult.class);

            return result.getBody();
        } catch (Exception e) {
            return null;
        }
    }
    private static String httpPost(String url, String content){

        try {
            StringEntity stringEntity = new StringEntity(content, "utf-8");

            Header[] headers = new Header[] { new BasicHeader("X-Auth-Token", getToken()),
                    new BasicHeader("Content-Type", "application/json") };
            String result = HttpClientUtils.getHttpPostResult(url, headers, stringEntity);

            System.out.println(result);

            return result;
            /**
             * {"dataset_id": "2fff8bb3-c6d4-45f8-9a26-eb47b38c0fb4", "task_id": "2b16f332-492a-4f81-b258-074763556d4b"}
             */
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    private static String httpPut(String url, String content){

        try {
            StringEntity stringEntity = new StringEntity(content, "utf-8");

            Header[] headers = new Header[] { new BasicHeader("X-Auth-Token", getToken()),
                    new BasicHeader("Content-Type", "application/json") };
            String result = HttpClientUtils.getHttpPutResult(url, headers, stringEntity);

            System.out.println(result);

            return result;
            /**
             * {"dataset_id": "2fff8bb3-c6d4-45f8-9a26-eb47b38c0fb4", "task_id": "2b16f332-492a-4f81-b258-074763556d4b"}
             */
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    private static String httpGet(String url){

        try {
            Header[] headers = new Header[] { new BasicHeader("X-Auth-Token", getToken()),
                    new BasicHeader("Content-Type", "application/json") };
            String result = HttpClientUtils.getHttpGetResult(url, headers);

            System.out.println(result);

            return result;
            /**
             * {"dataset_id": "2fff8bb3-c6d4-45f8-9a26-eb47b38c0fb4", "task_id": "2b16f332-492a-4f81-b258-074763556d4b"}
             */
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    private static String httpDelete(String url){

        try {
            Header[] headers = new Header[] { new BasicHeader("X-Auth-Token", getToken()),
                    new BasicHeader("Content-Type", "application/json") };
            String result = HttpClientUtils.getHttpDeleteResult(url, headers, null);

            System.out.println(result);

            return result;
            /**
             * {"dataset_id": "2fff8bb3-c6d4-45f8-9a26-eb47b38c0fb4", "task_id": "2b16f332-492a-4f81-b258-074763556d4b"}
             */
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * 查询数据集
     */
    public static void queryDataSet(String dataSetId) throws Exception{
        String url = endPointUrl + "/v1/" + projectId + "/datasets/" + dataSetId;

        try {
            String result = httpGet(url);

            System.out.println(result);

            /**
             * {"dataset_id": "2fff8bb3-c6d4-45f8-9a26-eb47b38c0fb4", "name": "jaytest2", "description": "", "bucket_url": "jaytest/jay/", "create_time": 1562492166}
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询数据集列表
     */
    public static void queryAllDataSet() throws Exception{
        String url = endPointUrl + "/v1/" + projectId + "/datasets";

        try {
            String result = httpGet(url);

            System.out.println(result);

            /**
             * {
             *     "dataset_count": 2,
             *     "datasets": [
             *         {
             *             "dataset_id": "8338a096-4057-4d1b-ae66-e447f51e91d5",
             *             "dataset_name": "jaytest",
             *             "description": "",
             *             "data_url": "whitebowl/src/all/",
             *             "file_count": 2459,
             *             "create_time": 1562490641
             *         },
             *         {
             *             "dataset_id": "2fff8bb3-c6d4-45f8-9a26-eb47b38c0fb4",
             *             "dataset_name": "jaytest2",
             *             "description": "",
             *             "data_url": "jaytest/jay/",
             *             "file_count": 0,
             *             "create_time": 1562492166
             *         }
             *     ]
             * }
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 删除数据集
     */
    public static void deleteDataSet(String dataSetId) throws Exception{
        String url = endPointUrl + "/v1/" + projectId + "/datasets/" + dataSetId;

        try {
            String result = httpDelete(url);

            System.out.println(result);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 删除 OBS 文件
     */
    public static void deleteObs(String dataSetId) throws Exception{
        String url = endPointUrl + "/v1/" + projectId + "/datasets/" + dataSetId + "/files";

        try {
            String result = httpDelete(url);

            System.out.println(result);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 发布数据集版本
     */
    public static void deployDataSet(String dataSetId) throws Exception{
        String url = endPointUrl + "/v1/" + projectId + "/datasets/" + dataSetId + "/versions";

        try {
            String result = httpPost(url, null);

            System.out.println(result);

            Map<String, Object> map = JsonUtil.parse(result);

            System.out.println(map.get("version_id"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询数据集版本详情
     */
    public static void queryDataSetVersion(String dataSetId, String versionId) throws Exception{
        String url = endPointUrl + "/v1/" + projectId + "/datasets/" + dataSetId + "/versions/" + versionId;

        try {
            String result = httpGet(url);

            System.out.println(result);

            Map<String, Object> map = JsonUtil.parse(result);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 查看数据集任务状态
     */
    public static void queryDataSetStatus(String taskId) throws Exception{
        String url = endPointUrl + "/v1/" + projectId + "/datasets/task/" + taskId;

        try {
            String result = httpGet(url);

            System.out.println(result);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 创建数据标注作业
     */
    public static void createAnnotationJob(String jobName) throws Exception{
        String url = endPointUrl + "/v1/" + projectId + "/annotation-jobs";

        try {
            com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
            json.put("name", jobName);
            json.put("data_type", "OBS");//obs or filter job
            json.put("path", "jaytest/jay/");
//            json.put("filter_id", "jaytest/jay/");

            /**
             * 人工标注类型：
             * l 图片分类：“Manual Image classify”。
             * l 物体检测：“Manual Object detection”。
             */
            json.put("type", "Manual Object detection");
            json.put("open_obs_version", "true");
            String requestBody = json.toJSONString();

            System.out.println(requestBody);

            String result = httpPost(url, requestBody);

            System.out.println(result);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询数据标注作业列表
     */
    public static void queryAnnotationJobs() throws Exception{
        String url = endPointUrl + "/v1/" + projectId + "/annotation-jobs?offset=1&limit=10&sort_by=create_time&order=desc";
//        String url = endPointUrl + "/v1/" + projectId + "/annotation-jobs?offset=1&limit=10&sort_by=create_time&order=desc&search_content=%s%";

        try {
            String result = httpGet(url);

            System.out.println(result);

            /**
             * {
             *     "job_total_count": 0,
             *     "third_annotation_count_limit": 100,
             *     "manual_annotation_count_limit": 100,
             *     "jobs": [],
             *     "tenant_id": "15e57275e77c496dbef73cc6ac8c203c"
             * }
             */
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     *  删除数据标注作业
     */
    public static void deleteAnnotationJobs(String jobId) throws Exception{
        String url = endPointUrl + " /v1/" + projectId + "/annotation-jobs/" + jobId;

        try {
            String result = httpDelete(url);

            System.out.println(result);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     *  保存标注作业的校验结果
     */
    public static void validationAnnotationJobs(String jobId) throws Exception{
        String url = endPointUrl + " /v1/" + projectId + "/annotation-jobs/" + jobId + "/validation";

        try {
            com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
            json.put("pass_rate", "60.00");
            String requestBody = json.toJSONString();

            System.out.println(requestBody);

            String result = httpPost(url, requestBody);

            System.out.println(result);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Demo代码，简介ImageSearch使用功能
     */
    public static void main2(String[] args) throws URISyntaxException, UnsupportedOperationException, IOException
    {

//        String username = "jenchxin";    // 此处，请输入用户名
//        String password = "shdy1qaz";      // 此处，请输入对应用户名的密码
//        String projectName = "cn-north-1"; // 此处，请输入服务的区域信息，参考地址: http://developer.huaweicloud.com/dev/endpoint
//
//        String projectId = "0564386397000fb82f09c01d0696f66e"; //从我的凭证，项目列表中获取
//        String instanceName = "imagesearch-d6g2";//实例名称
        String region = "cn-north-1"; // 此处，请输入服务的区域信息，参考地址: http://developer.huaweicloud.com/dev/endpoint
        String service = "cn-north-1a"; // 此处，请输入可用分区名称，参考地址: http://developer.huaweicloud.com/dev/endpoint
//        String ak = "LX1UUUTAIDRYH2UTP4AG"; //ak,sk从我的凭证，管理访问秘钥中获取
//        String sk = "NHFZfWF1Fqor0q8oYvj5tJy65mXZcJhkiguvS5LZ";
        //使用ak/sk进行鉴权，推荐使用此方式
        ImageSearchService imageSearchService = new ImageSearchService(service, region, ak, sk);

        //使用用户名密码获取token，后续使用token进行鉴权
        String token = TokenUtil.getToken(username, password, projectName); //获取token
        System.out.println(token);
        //使用token进行鉴权的方式
        /*ImageSearchService imageSearchService2 = new ImageSearchService(token);


        //根据用户名和模型创建实例
        ArrayList<String> createServiceTag = new ArrayList<>();
        createServiceTag.add("Tag1");
        createServiceTag.add("Tag2");
        printResult(imageSearchService.requestCreateService(projectId, instanceName, "image-copyright",
                "register service for user model test.",
                createServiceTag,
                1000000));
        //添加图像索引，使用图像的Base64
        HashMap<String, String> createIndexTags = new HashMap<>();
        createIndexTags.put("Tag1","test-image");
        printResult(imageSearchService.requestCreateIndexBase64(projectId, instanceName, "data/is-demo-1.jpg",
                "/Users/jay/IdeaProjects/binguo/api/src/main/resources/static/baozi.jpeg",createIndexTags));

        //添加图像索引，使用图像的URL(当前仅支持OBS图像的URL)
        printResult(imageSearchService.requestCreateIndexUrl(projectId, instanceName,
                "https://bucketName.obs.myhwclouds.com/image/test1.jpg", createIndexTags));


        //搜索相似图像，使用图像的Base64
        printResult(imageSearchService.requestSearchSimBase64(projectId, instanceName, "data/is-demo-2.jpg",
                10, 0, null));

        //搜索相似图像，使用图像的URL(当前仅支持OBS图像的URL)
        printResult(imageSearchService.requestSearchSimUrl(projectId, instanceName, "https://bucketName.obs.myhwclouds.com/image/test2.jpg",
                10, 0 , null));

        //搜索相似图像,使用图像标签
        printResult(imageSearchService.requestSearchSimTags(projectId, instanceName, 10, 0,createIndexTags));

        //给定源实例中多个图片路径，到目标实例中搜索相同或相似图片。目前仅图库模型支持该接口，其他模型暂不支持。
        ArrayList<String> crossSearchPath = new ArrayList<>();
        crossSearchPath.add("https://bucketName.obs.myhwclouds.com/image/test1.jpg");
        crossSearchPath.add("https://bucketName.obs.myhwclouds.com/image/test2.jpg");
        printResult(imageSearchService.requestCrossSearch(projectId, 10, 0, crossSearchPath,
                instanceName, "test-instance-2"));


       //查询图像索引是否存在
        printResult(imageSearchService.requestImageCheck(projectId, instanceName, "https://bucketName.obs.myhwclouds.com/image/test1.jpg"));

        //通过图片路径删除索引库中对应图片
        printResult(imageSearchService.requestDeleteIndex(projectId, instanceName, "https://bucketName.obs.myhwclouds.com/image/test1.jpg"));

        //修改图像索引库中已存在的图片信息
        printResult("修改" + imageSearchService.requestUpdateTags(projectId, instanceName, "https://bucketName.obs.myhwclouds.com/image/test1.jpg", createIndexTags));

        // 查询用户实例信息
        printResult(imageSearchService.requestGetServiceInfo(projectId, instanceName));

        //删除实例
        printResult(imageSearchService.requestDeleteService(projectId, instanceName));*/
    }


    private static void printResult(String result){
        if(null == result){
            System.out.println("调用服务接口失败");
        }else{
            System.out.println(result);
        }
    }
}
